package com.yanggeng.demo.beginnerguidedemo.utils;

import android.support.design.widget.BaseTransientBottomBar;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.yanggeng.demo.beginnerguidedemo.R;

/**
 * Created by yanggeng on 2017/6/30.
 */

public class SnackbarUtil {

    private static int backgroundColor = 0xFF2B88E5;
    private static int textColor = 0xFFFFFFFF;

    /**
     * 短显示Snackbar
     * @param view
     * @param text
     */
    public static void shortSnackbar(View view, String text) {
        shortSnackbar(view, text, backgroundColor, textColor);
    }

    public static void shortSnackbar(View view, String text, int backgroundColor, int textColor) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
        View snackbarView = snackbar.getView();
        snackbarView.setBackgroundColor(backgroundColor);
        ((TextView)snackbarView.findViewById(R.id.snackbar_text)).setTextColor(textColor);
        snackbar.show();
    }

    /**
     * 长显示Snackbar
     * @param view
     * @param text
     */
    public static void longSnackbar(View view, String text) {
        longSnackbar(view, text, backgroundColor, textColor);
    }

    public static void longSnackbar(View view, String text, int backgroundColor, int textColor) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_LONG);
        View snackbarView = snackbar.getView();
        snackbarView.setBackgroundColor(backgroundColor);
        ((TextView)snackbarView.findViewById(R.id.snackbar_text)).setTextColor(textColor);
        snackbar.show();
    }

    public static void snackbarButton(View view, String text, String actionText, View.OnClickListener onClickListener) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction(actionText, onClickListener);
        View snackbarView = snackbar.getView();
        snackbarView.setBackgroundColor(backgroundColor);
        ((TextView)snackbarView.findViewById(R.id.snackbar_text)).setTextColor(textColor);
        ((Button)snackbarView.findViewById(R.id.snackbar_action)).setTextColor(textColor);
        snackbar.show();
    }

}
